# 1、导包
import unittest
import requests
# 2、创建用例
class IhrmText(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.login_url = "http://ihrm-test.itheima.net/api/sys/login"
        cls.user_info_url = "http://ihrm-test.itheima.net/api/sys/profile"
        # 2.3 请求头
        cls.header = {"Content-Type": "application/json"}

    def test01_lgin(self):
        self.data = {
            "mobile": "13800000002",
            "password": "123456"
        }
        response = requests.post(url=self.login_url, json=self.data, headers=self.header)
        # 4、查看结果/断言
        self.assertEqual(True,response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertEqual("操作成功！", response.json().get("message"))
        # print(response.json().get("data"))
        self.header["Authorization"] = "Bearer " + response.json().get("data")
        # print(response.json())

    def test02_userinfo(self):
        response = requests.post(url=self.user_info_url, headers=self.header)
        print(response.json())
        self.assertEqual(True,response.json().get("success"))
        self.assertEqual(10000, response.json().get("code"))
        self.assertEqual("操作成功！", response.json().get("message"))

    def test03_lgin(self):
        self.data = {
            "mobile": "1380000000",
            "password": "123456"
        }
        response = requests.post(url=self.login_url,json=self.data,headers = self.header)
        # 4、查看结果
        print(response.json())
        self.assertEqual(False,response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual("用户名或密码错误", response.json().get("message"))

    def test04_lgin(self):
        self.data = {
            "mobile": "",
            "password": "123456"
        }
        response = requests.post(url=self.login_url,json=self.data,headers = self.header)
        # 4、查看结果
        print(response.json())
        self.assertEqual(False,response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual("用户名或密码错误", response.json().get("message"))

    def test05_lgin(self):
        self.data = {
            "mobile": "13800000002",
            "password": "12345"
        }
        response = requests.post(url=self.login_url,json=self.data,headers = self.header)
        # 4、查看结果
        print(response.json())
        self.assertEqual(False,response.json().get("success"))
        self.assertEqual(20001, response.json().get("code"))
        self.assertEqual("用户名或密码错误", response.json().get("message"))

